package com.kabigon.tiny.config;

import com.kabigon.tiny.anno.CurrentUser;
import com.kabigon.tiny.domain.sysuser.SysUser;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

/**
 * @author xu.biao
 * @version v1.0
 * @Package com.kabigon.tiny.config
 * @data 2023-07-30 15:36
 */
public class LoginUserArgumenResolver implements HandlerMethodArgumentResolver {
    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        //return parameter.getParameterType().equals(SysUser.class);
        return parameter.hasParameterAnnotation(CurrentUser.class) && parameter.getParameterType().equals(SysUser.class);
    }

    @Override
    public SysUser resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
        SysUser sysUser = new SysUser();
        sysUser.setUserId(1L);
        sysUser.setUserName("张三疯");
        return sysUser;
    }
}
